<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,myUser-scalable=no">
    <title>登录界面</title>
    <link rel="stylesheet" href="css/style.css">
</head>

<body>
<div class="container">
    <div class="form-box">
        <!-- 注册 -->
        <form action="/reg" class="register-box hidden">
            <input type="hidden" id="purpose" value="worker" name="role">
                <h1>注册</h1>
                <input type="text" placeholder="用户名" name="username">
                <input type="email" placeholder="邮箱" name="email">
                <input type="password" placeholder="密码" name="password">
                <input type="password" placeholder="确认密码" name="pwdAgain">
            <div class="purpose-row">
                <span class="cur" id="findJob">我要找工作</span>
                <span class="" id="findWorker">我要招聘</span>
            </div>
                <button>注册</button>

        </form>

        <!-- 登录 -->
        <form th:action="@{/login}" class="login-box" method="post">
                <h1>登陆</h1>
                <input type="text" placeholder="用户名" name="username">
                <input type="password" placeholder="密码" name="password">
                <p class="error-note" th:if="${param.error}!=null">用户名或密码错误！</p>
                <button>登录</button>
        </form>

    </div>
    <div class="con-box left">
        <h2>欢迎来到<span>承志</span></h2>
        <p>快来寻找你的专属<span>工作</span>吧</p>
        <img src="images/logo.png" alt="">
        <p>已有账号</p>
        <button id="login">去登录</button>
    </div>
    <div class="con-box right">
        <h2>欢迎来到<span>承志</span></h2>
        <p>快来寻找你的专属<span>工作</span>吧</p>
        <img src="images/logo.png" alt="">
        <p>没有账号？</p>
        <button id="register">去注册</button>
    </div>
</div>


<script>
    // 要操作到的元素
    let login=document.getElementById('login');
    let register=document.getElementById('register');
    let form_box=document.getElementsByClassName('form-box')[0];
    let register_box=document.getElementsByClassName('register-box')[0];
    let login_box=document.getElementsByClassName('login-box')[0];
    let find_job=document.getElementById('findJob');
    let find_worker=document.getElementById('findWorker');
    let purpose_value=document.getElementById('purpose');

    // 去注册按钮点击事件
    register.addEventListener('click',()=>{
        form_box.style.transform='translateX(80%)';
        login_box.classList.add('hidden');
        register_box.classList.remove('hidden');
    })
    // 去登录按钮点击事件
    login.addEventListener('click',()=>{
        form_box.style.transform='translateX(0%)';
        register_box.classList.add('hidden');
        login_box.classList.remove('hidden');
    })
    // "我要找工作"点击事件
    find_job.addEventListener('click',()=>{
        find_job.classList.add('cur');
        find_worker.classList.remove('cur');
        purpose_value.setAttribute("value","worker");
        purpose_value.setAttribute("name","role");

    })

    // "我要招聘"点击事件
    find_worker.addEventListener('click',()=>{
        find_job.classList.remove('cur');
        find_worker.classList.add('cur');
        purpose_value.setAttribute("value","boss");
        purpose_value.setAttribute("name","role");

    })

</script>

</body>

</html>
